﻿<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %> 
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ViewAlbumUserControl.ascx.cs" Inherits="JM.JCY.SharePointComponent.PhotoAlbum.ViewAlbum.ViewAlbumUserControl" %>

<link href="/_layouts/NCS.OCP.Resource/styles/OCPStyle.css" rel="stylesheet" type="text/css" />
<style type="text/css">
    #imagebox
    {
        border: 1px solid #B8B8B8;
        background-color: #ffffff;
        padding: 4px;
        border-bottom: 1px solid #B8B8B8;
    }
    
    .editcss, .commoncss
    {
        padding: 3px 0 0 10px;
        float: right;
    }
</style>

<script type="text/javascript">

    var belongto = null;
    var currentgroup = null;
    var enable = null;
    var albumurl = null;

    var wcfUrl = funHeartWorkUrl;
    var wcfnewsfeedUrl = newsfeedSvcUrl;

    $(document).ready(function () {

        var staffContextId = $("#<%=HiddenFieldStaffContextId.ClientID %>").val();
        if (staffContextId != '') {

            location.href = "/MySite/default.aspx?ContextId=" + staffContextId;
        }

        var AlbumId = $("#<%=HiddenAlbumId.ClientID %>").val();
        var lastUpdatedTime = $("#<%=HiddenLastUpdatedTime.ClientID %>").val();

        $("#timeagoSpan").text($.timeago(lastUpdatedTime));

        var lbBackHome = $("#<%=lbBackHome.ClientID %>");
        lbBackHome.live('click', function () {

            location.href = "ViewAllAlbums.aspx?ContextId=" + $("#<%=HiddenContextId.ClientID %>").val();
            return false;
        });

        var lbBackHome2 = $("#<%=lbBackHome2.ClientID %>");
        lbBackHome2.live('click', function () {

            location.href = "ViewAllAlbums.aspx?ContextId=" + $("#<%=HiddenContextId.ClientID %>").val();
            return false;
        });

        var lbAddMoreMedia = $("#<%=lbAddMoreMedia.ClientID %>");
        lbAddMoreMedia.live('click', function () {
            if (belongto == currentgroup) {
                location.href = "AddMoreMedia.aspx?AlbumId=" + AlbumId + "&ContextId=" + $("#<%=HiddenContextId.ClientID %>").val();
            } else {
                var msg = "This album belongs to " + belongto + ".You can only add media if you are in the " + belongto + " Site. Do you want to proceed to switch to " + belongto + " site?";
                showConfirm('', msg, AddMoreMediaYesCall, CancelCall, null);
            }
            return false;
        });

        var lbEditThisAlbum = $("#<%=lbEditThisAlbum.ClientID %>");
        lbEditThisAlbum.live('click', function () {
            if (belongto == currentgroup) {
                location.href = "EditAlbum.aspx?AlbumId=" + AlbumId + "&ContextId=" + $("#<%=HiddenContextId.ClientID %>").val();
            } else {
                var msg = "This album belongs to " + belongto + ".You can only edit this album if you are in the " + belongto + " Site. Do you want to proceed to switch to " + belongto + " site?";
                showConfirm('', msg, EditAlbumYesCall, CancelCall, null);
            }
            return false;
        });

        var lbRemoveThisAlbum = $("#<%=lbRemoveThisAlbum.ClientID %>");
        lbRemoveThisAlbum.live('click', function () {
            if (belongto != currentgroup) {
                var msg = "This album belongs to " + belongto + ".You can only remove this album if you are in the " + belongto + " Site. Do you want to proceed to switch to " + belongto + " site?";
                showConfirm('', msg, RemoveAlbumYesCall, CancelCall, null);
            } else {
                showConfirm('', "You are going to remove this album. Please confirm your request.", RemoveAlbumDoCall, CancelCall, null);
            }
            return false;
        });
        checkCanBeEdited();
        // pagings
        SetCurrentLink(1);

        var isRemoveAlbum = $("#<%=HiddenFieldRemoveAblum.ClientID %>").val();
        if (isRemoveAlbum == "T") {
            $("#<%=HiddenFieldRemoveAblum.ClientID %>").val("F");
            showConfirm('', "You are going to remove this album. Please confirm your request.", RemoveAlbumDoCall, CancelCall, null);
        }

        Showpagination();
    });

    function AddMoreMediaYesCall() {
        var AlbumId = $("#<%=HiddenAlbumId.ClientID %>").val();
        var tranid = "e02dea5198ca48b4a2c75171d316e210";
        location.href = albumurl + "/AddMoreMedia.aspx?AlbumId=" + AlbumId + "&tranid=" + tranid + "&ContextId=" + $("#<%=HiddenFieldTargetContextId.ClientID %>").val();
    }

    function EditAlbumYesCall() {
        var AlbumId = $("#<%=HiddenAlbumId.ClientID %>").val();
        var tranid = "e02dea5198ca48b4a2c75171dsdfsdfswe";
        location.href = albumurl + "/EditAlbum.aspx?AlbumId=" + AlbumId + "&tranid=" + tranid + "&ContextId=" + $("#<%=HiddenFieldTargetContextId.ClientID %>").val();
    }

    function RemoveAlbumYesCall() {
        var AlbumId = $("#<%=HiddenAlbumId.ClientID %>").val();
        var tranid = "e02dea5198caadcb1231cc210";
        location.href = albumurl + "/ViewAlbum.aspx?AlbumId=" + AlbumId + "&tranid=" + tranid + "&ContextId=" + $("#<%=HiddenFieldTargetContextId.ClientID %>").val();
    }

    function RemoveAlbumDoCall() {
        __doPostBack("removeAlbum");
    }
    function CancelCall() {
        //Do Nothing.
    }

    function checkCanBeEdited() {
        enable = $("#<%=HiddenFieldEableEdit.ClientID %>").val();
        belongto = $("#<%=HiddenFieldBelongedGroup.ClientID %>").val();
        currentgroup = $("#<%=HiddenFieldCurrentGroup.ClientID %>").val();
        albumurl = $("#<%=HiddenFieldAlbumUrl.ClientID %>").val();
        if (enable == "T") {
            $("#divedit").css("display", "block");
        } else {
            $("#divedit").css("display", "none");
        }
    }
    function turnPage(pageIndex) {
        $("#currIndex").val(pageIndex);
        SetCurrentLink(pageIndex);
        CallServer(pageIndex, 'content');
    }

    function turnPagePrev() {

        var prevIndex = parseInt($("#currIndex").val());
        var currentIndex = 1;
        if (prevIndex > 1)
            currentIndex = prevIndex - 1;
        $("#currIndex").val(currentIndex);
        SetCurrentLink(currentIndex);
        CallServer(currentIndex, 'content');
    }

    function turnPageNext() {

        var prevIndex = parseInt($("#currIndex").val());
        var currentIndex = $("#lastIndex").val();
        if (prevIndex < $("#lastIndex").val())
            currentIndex = prevIndex + 1;
        $("#currIndex").val(currentIndex);
        SetCurrentLink(currentIndex);
        CallServer(currentIndex, 'content');
    }

    function turnPageLast() {

        var currentIndex = $("#lastIndex").val();
        $("#currIndex").val(currentIndex);
        SetCurrentLink(currentIndex);
        CallServer(currentIndex, 'content');
    }

    function ReceiveCallback(arg, context) {
        var container = document.getElementById(context);
        container.innerHTML = arg;
    }

    function SetCurrentLink(currentIndex) {

        var lastIndex = $("#lastIndex").val();
        var i;
        for (i = 1; i <= lastIndex; i++) {
            if (i == currentIndex)
                $("#a" + i).css('text-decoration', 'underline');
            else
                $("#a" + i).css('text-decoration', 'none');
        }

        //Set First,Previous,Next, Last button enable or disable
        if (currentIndex == 1) {
            $("#lbFirst").attr("disabled", "true");
            $("#lbPrev").attr("disabled", "true");
        }
        else {
            $("#lbFirst").removeAttr("disabled");
            $("#lbPrev").removeAttr("disabled");
        }

        if (currentIndex == lastIndex) {
            $("#lbNext").attr("disabled", "true");
            $("#lbLast").attr("disabled", "true");
        }
        else {
            $("#lbNext").removeAttr("disabled");
            $("#lbLast").removeAttr("disabled");
        }
    }

    function copyclick() {
        clipboardData.setData('text', window.location.href)
    }

    function getSharepointObjectId() {

        var sharepointObjectId = $("#<%=HiddenObjectId.ClientID %>").val();
        return sharepointObjectId;
    }

    function getMediaID() {
        return 0;
    }

    function getCurrentUrl() {
        return "a|b";
    }

    function getStaffId() {
        var staffId = $("#<%=HiddenStaffId.ClientID %>").val();
        return staffId;
    }

    function getApplicationId() {
        var ApplicationId = $("#<%=HiddenAppId.ClientID %>").val();
        return ApplicationId;

    }

    function getContextId() {
        var ContextId = $("#<%=HiddenContextId.ClientID %>").val();
        return ContextId;

    }

    function getSharingOption() {
        var SharingOption = $("#<%=HiddenSharingOption.ClientID %>").val();
        return SharingOption;

    }

    function redirectComment() {
        var txtComment = $("#txtComment");
        txtComment.focus();

    }

    function clickLike(spobjectId, btnlikeId, lbllikenumId, objectType) {

        var staffId = $("#<%=HiddenStaffId.ClientID %>").val();
        jQuery.fn.likeCommit({
            staffid: staffId,
            spobjectid: spobjectId,
            objecttype: objectType,
            url: wcfnewsfeedUrl + "LikeOfFun",
            success: function (result) {
                getLikes(spobjectId, btnlikeId, lbllikenumId, staffId, objectType);
            }
        });
        return false;
    }
    function getLikes(mediaId, btnlikeId, lbllikenumId, staffId, objectType) {

        jQuery.fn.getLikes({
            staffid: getStaffId(),
            spobjectid: mediaId,
            objecttype: objectType,
            url: wcfnewsfeedUrl + "GetLikes",
            success: function (result) {

                if (result == "[]") {
                    showLikeNum(lbllikenumId, 0);
                    showLikeTitle(btnlikeId, "Like");
                } else {
                    var JSON = eval('(' + (result) + ')');
                    showLikeNum(lbllikenumId, JSON[0].count);
                    if (JSON[0].staffId == getStaffId()) {
                        showLikeTitle(btnlikeId, "Unlike");
                    } else {
                        showLikeTitle(btnlikeId, "Like");
                    }
                }
            }
        });
    }

    function showLikeNum(objId, likenum) {
        $("span[id='" + objId + "']").text(likenum);
    }
    function showLikeTitle(objId, likeTitle) {
        $("a[id='" + objId + "']").text(likeTitle);
    }

    function Showpagination() {
        var pageNum = $("#<%=HiddenFieldPageNum.ClientID %>").val();
        if (pageNum == 1) {
            $("div.pagination").css("display", "none");
            $("#backToAlbum").css("display", "block");
            $("#backToAlbum").addClass("pagination");
        }
    }
</script>
<div class="gallery">
    <table width="100%" class="galleryTitle">
        <tr>
            <td>
                <h2 class="gallery">
                    <img src="/_layouts/NCS.OCP.Resource/images/fun_work.png">
                    Fun@Work - View Album</h2>
            </td>
            <td align="right" class="link">
                <div id="divcom" class="editcss">
                    <asp:LinkButton ID="lbViewSlideShow" CssClass="galleryDetail" runat="server">View Slideshow</asp:LinkButton>
                    | <a class="galleryDetail" href="javascript:copyclick();">Copy URL</a> | <a class="galleryDetail"
                        href="javascript:window.print();">Print This Page</a></div>
                <div id="divedit" class="editcss">
                    <asp:LinkButton ID="lbAddMoreMedia" CssClass="galleryDetail" runat="server">Add More Media</asp:LinkButton>
                    |
                    <asp:LinkButton ID="lbEditThisAlbum" CssClass="galleryDetail" runat="server">Edit This Album</asp:LinkButton>
                    |
                    <asp:LinkButton ID="lbRemoveThisAlbum" CssClass="galleryDetail" runat="server" OnClick="lbRemoveThisAlbum_Click">Remove This Album</asp:LinkButton>
                    |</div>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <asp:Label ID="lblAlbumName" CssClass="gallery" runat="server"></asp:Label>
            </td>
        </tr>
        <tr>
            <td>
                <h2 class="galleryDetail">
                    <asp:Label ID="lblCreater" runat="server"></asp:Label></h2>
            </td>
            <td align="right">
                <div id="backToAlbum" style="display:none">
                    <asp:LinkButton ID="lbBackHome2" runat="server" CssClass="link" Font-Size="12px" >Back to Albums</asp:LinkButton>
                </div>
                <div class="pagination">
                    <asp:LinkButton ID="lbBackHome" runat="server" CssClass="link" Font-Size="12px" >Back to Albums</asp:LinkButton>
                    &nbsp;&nbsp;
                    <asp:LinkButton ID="lbFirst" runat="server" Text="<< First" class="galleryDetailOfpagination"
                        OnClientClick="turnPage(1);return false;"></asp:LinkButton>
                    <asp:Label ID="lbl2" runat="server" Text="|"></asp:Label>
                    <asp:LinkButton ID="lbPrev" runat="server" Text="< Previous" class="galleryDetailOfpagination"
                        OnClientClick='turnPagePrev();return false;'></asp:LinkButton>
                    <asp:Label ID="lbl4" runat="server" Text="|"></asp:Label>
                    <asp:LinkButton ID="lbNext" runat="server" Text="Next >" class="galleryDetailOfpagination" OnClientClick='turnPageNext();return false;'></asp:LinkButton>
                    <asp:Label ID="lbl5" runat="server" Text="|"></asp:Label>
                    <asp:LinkButton ID="lbLast" runat="server" Text="Last >>" class="galleryDetailOfpagination" OnClientClick='turnPageLast();return false;'></asp:LinkButton>
                    <input id="currIndex" type="text" value="1" style="display: none;" />
                    <input id="lastIndex" type="text" value="<%=lastIndex%>" style="display: none;" />
                </div>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <asp:Image ID="imgContextIcon" runat="server" />
                <asp:Label ID="lblContextAcronym" CssClass="gallery" runat="server"></asp:Label>
            </td>
        </tr>
    </table>
    <br />
    <div id="content">
        <asp:DataList ID="DatalistViewAlbum" runat="server" RepeatColumns="5" CellPadding="4"
            OnItemDataBound="DatalistViewAlbum_OnItemDataBound" CellSpacing="2" DataKeyField="AlbumContentId"
            RepeatDirection="Horizontal">
            <ItemTemplate>
                <div>
                    <table>
                        <tr>
                            <td>
                                <div class="ThumbNailImg">
                                    <div id="imagebox">
                                        <asp:Literal ID="LiteralViewMedia" runat="server"></asp:Literal>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        <tr id="Tr1" runat="server">
                            <td>
                                <div class="ThumbNailImg">
                                    <asp:Image ID="imgLike" runat="server" ImageUrl="/_layouts/NCS.OCP.Resource/images/thumbs-up.gif" />
                                    <asp:Label ID="lblLikeCount" CssClass="gallery" runat="server" Text="10"></asp:Label>
                                    <asp:LinkButton ID="lkbLike" runat="server" Text="Like" CssClass="galleryDetail"></asp:LinkButton>
                                </div>
                            </td>
                        </tr>
                    </table>
                </div>
            </ItemTemplate>
        </asp:DataList>
    </div>
    <table width="100%" class="thumbnail">
        <tr>
            <td colspan="5" class="albumdesc">
                <asp:Label ID="lblAlbumDesc" CssClass="gallery" runat="server"></asp:Label>
            </td>
        </tr>
        <tr>
            <td>
                <h2 class="galleryDetail">
                    <span id="timeagoSpan"></span>&nbsp;|&nbsp;<a class="galleryDetail"
                        href="javascript:redirectComment();">Comment</a>
                   </h2>
            </td>
        </tr>
        <tr>
            <td colspan="4" align="right">
                <div class="pagination">
                    <asp:LinkButton ID="lbFirstDown" runat="server" Text="<< First" class="galleryDetailOfpagination"
                        OnClientClick="turnPage(1);return false;"></asp:LinkButton>
                    <asp:Label ID="Label1" runat="server" Text="|"></asp:Label>
                    <asp:LinkButton ID="lbPrevDown" runat="server" Text="< Previous" class="galleryDetailOfpagination"
                        OnClientClick='turnPagePrev();return false;'></asp:LinkButton>
                    <asp:Label ID="Label2" runat="server" Text="|"></asp:Label>
                    <asp:LinkButton ID="lbNextDown" runat="server" Text="Next >" class="galleryDetailOfpagination"
                        OnClientClick='turnPageNext();return false;'></asp:LinkButton>
                    <asp:Label ID="Label3" runat="server" Text="|"></asp:Label>
                    <asp:LinkButton ID="lbLastDown" runat="server" Text="Last >>" class="galleryDetailOfpagination"
                        OnClientClick='turnPageLast();return false;'></asp:LinkButton>
                    <input id="currIndexDown" type="text" value="1" style="display: none;" />
                    <input id="lastIndexDown" type="text" value="<%=lastIndex%>" style="display: none;" />
                </div>
            </td>
        </tr>
    </table>
    <asp:HiddenField ID="HiddenFieldViewAlbumUrl" runat="server" />
    <asp:HiddenField ID="HiddenAlbumId" runat="server" />
    <asp:HiddenField ID="HiddenObjectId" runat="server" />
    <asp:HiddenField ID="HiddenStaffId" runat="server" />
    <asp:HiddenField ID="HiddenFieldEableEdit" runat="server" />
    <asp:HiddenField ID="HiddenFieldCurrentGroup" runat="server" />
    <asp:HiddenField ID="HiddenFieldBelongedGroup" runat="server" />
    <asp:HiddenField ID="HiddenAppId" runat="server" />
    <asp:HiddenField ID="HiddenContextId" runat="server" />
    <asp:HiddenField ID="HiddenSharingOption" runat="server" />
    <asp:HiddenField ID="HiddenLastUpdatedTime" runat="server" />
    <asp:HiddenField ID="HiddenFieldAlbumUrl" runat="server" />
    <asp:HiddenField ID="HiddenFieldRemoveAblum" runat="server" />
    <asp:HiddenField ID="HiddenFieldStaffContextId" runat="server" />
    <asp:HiddenField ID="HiddenFieldTargetContextId" runat="server" />
    <asp:HiddenField ID="HiddenFieldPageNum" runat="server" />
</div>